// packageE/suspendbutton/suspendbutton.js
Component({
  properties: {
    datas: {
      type: null,
    },
    component_id: {
      type: null,
    },
  },
  // 私有数据，可用于模板渲染
  data: {
    emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
    openImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/open.png",
    clientWidth: "375",
    isFold: false,

    iPnoneBottomBol: false,
    showcarrfootBol: true,
  },

  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {
      console.log(this.data.datas,'ddddddddddd12121')
    },
    moved() {},
    detached() {},
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {},
  // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {
    this.getiPnoneBottom();
    this.setData({
      clientWidth: wx.getSystemInfoSync().windowWidth,
    });
  },

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() {},
    hide() {},
    resize() {},
  },
  methods: {
    getiPnoneBottom() {
      let that = this;
      try {
        var value = wx.getStorageSync("iPhoneBottom");
        if (value) {
          that.setData({
            iPnoneBottomBol: true,
          });
          // Do something with return value
        }
      } catch (e) {
        // Do something when catch error
      }
    },
    toOpen() {
      this.setData({
        isFold: !this.data.isFold,
      });
    },
    goimgurl(e) {
      let item = e.currentTarget.dataset.item;
      if (item.is_minApp == 2) {
        if (item.gh_id) {
          if (item.minApp_link) {
            try {
              wx.navigateToMiniProgram({
                appId: item.gh_id,
                path: item.minApp_link,
                extraData: {},
                envVersion: "release",
                success(res) {
                  // 打开成功
                },
                fail(res) {
                  wx.showToast({
                    title: "小程序跳转失败",
                    icon: "none",
                    duration: 2000,
                  });
                },
              });
            } catch (e) {
              wx.showToast({
                title: "小程序跳转失败",
                icon: "none",
                duration: 2000,
              });
            }
          } else {
            wx.showToast({
              title: "请设置跳转小程序后的跳转链接",
              icon: "none",
              duration: 2000,
            });
          }
        } else {
          wx.showToast({
            title: "请设置小程序所需跳转appId",
            icon: "none",
            duration: 2000,
          });
        }
      } else if (item.is_minApp == 3) {
        wx.makePhoneCall({
          phoneNumber: item.phone,
          success: function () {
            console.log("拨打成功");
          },
          fail: function () {
            console.log("拨打失败");
          },
        });
      } else if (item.is_minApp == 4) {
        // 小程序客服
      } else if (item.is_minApp == 5) {
        // 海报
        this.openQrCode("block",item.poster_id);
      } else {
        let url = item.h5_link;
        try {
          wx.navigateTo({
            url: url,
          });
        } catch (e) {
          wx.showToast({
            title: "链接设置错误",
            icon: "none",
            duration: 2000,
          });
        }
      }
    },
    openQrCode(e,poster_id) {
      this.setData({
        isshow: true,
        poster_id: poster_id
      });
    },
    // 隐藏二维码
    clicktapshow() {
      this.setData({
        isshow: false,
        lsgow: false,
      });
    },
  },
});
